package com.ruoyi.sys.emeknowledge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.emeknowledge.domain.TbEmergencyKnowledge;
import com.ruoyi.sys.emeknowledge.service.ITbEmergencyKnowledgeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应急知识库Controller
 * 
 * @author iuxin
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/emergencyKnowledge/knowledge")
public class TbEmergencyKnowledgeController extends BaseController
{
    @Autowired
    private ITbEmergencyKnowledgeService tbEmergencyKnowledgeService;

    /**
     * 查询应急知识库列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEmergencyKnowledge tbEmergencyKnowledge)
    {
        startPage();
        List<TbEmergencyKnowledge> list = tbEmergencyKnowledgeService.selectTbEmergencyKnowledgeList(tbEmergencyKnowledge);
        return getDataTable(list);
    }

    /**
     * 导出应急知识库列表
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:export')")
    @Log(title = "应急知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEmergencyKnowledge tbEmergencyKnowledge)
    {
        List<TbEmergencyKnowledge> list = tbEmergencyKnowledgeService.selectTbEmergencyKnowledgeList(tbEmergencyKnowledge);
        ExcelUtil<TbEmergencyKnowledge> util = new ExcelUtil<TbEmergencyKnowledge>(TbEmergencyKnowledge.class);
        util.exportExcel(response, list, "应急知识库数据");
    }

    /**
     * 获取应急知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:query')")
    @GetMapping(value = "/{ekId}")
    public AjaxResult getInfo(@PathVariable("ekId") Long ekId)
    {
        return AjaxResult.success(tbEmergencyKnowledgeService.selectTbEmergencyKnowledgeByEkId(ekId));
    }

    /**
     * 新增应急知识库
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:add')")
    @Log(title = "应急知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEmergencyKnowledge tbEmergencyKnowledge)
    {
        return toAjax(tbEmergencyKnowledgeService.insertTbEmergencyKnowledge(tbEmergencyKnowledge));
    }

    /**
     * 修改应急知识库
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:edit')")
    @Log(title = "应急知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEmergencyKnowledge tbEmergencyKnowledge)
    {
        return toAjax(tbEmergencyKnowledgeService.updateTbEmergencyKnowledge(tbEmergencyKnowledge));
    }

    /**
     * 删除应急知识库
     */
    @PreAuthorize("@ss.hasPermi('emergencyKnowledge:knowledge:remove')")
    @Log(title = "应急知识库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ekIds}")
    public AjaxResult remove(@PathVariable Long[] ekIds)
    {
        return toAjax(tbEmergencyKnowledgeService.deleteTbEmergencyKnowledgeByEkIds(ekIds));
    }
}
